<link href="<?php echo base_url('resources'); ?>/css/user/duan_style.css" rel="stylesheet" type="text/css" />
<script src="<?php echo base_url('resources/jquery-ui-1.10.3/jquery-1.9.1.js');?>"></script>
<script src="<?php echo base_url('resources/jquery-ui-1.10.3/ui/jquery-ui.js');?>"></script>
<div id="menuduan">
    <ul id="menuduan-menu">
        <li><a href="<?php echo base_url('nhanvien/duan/HienThiDanhSachNhiemVu?id='). $duan;?>">Nhiệm vụ</a></li>
        <li><a href="<?php echo base_url('nhanvien/duan/XemHoiThoaiTraoDoi?id='). $duan;?>">Hội thoại trao đổi</a></li>
        <li><a href="<?php echo base_url('nhanvien/duan/XemDanhSachBaoCaoDinhKy?id='). $duan;?>">Báo cáo định kỳ</a></li>
    </ul>
</div>
<div class="taomoi" id="lapbaocao">
    <form name="lapbaocao" action="<?php echo base_url('nhanvien/duan/LapBaoCao?id=').$duan; ?>" method="post" enctype="multipart/form-data">
        <input type="submit" value="LẬP BÁO CÁO" class="button" />
    </form>
</div>
<div id="locbaocao">
    <select name="locbaocao" onchange="locbaocao(this.value)">
        <?php
            for ($i=0; $i<sizeof($thanhvien); $i++){
                echo "<option value='{$thanhvien[$i]['MaHoSo']}'";
                if (isset($_GET['nv']) && ($_GET['nv'] == $thanhvien[$i]['MaHoSo'])) echo "selected='selected'";
                echo ">" .$thanhvien[$i]['HoTen']. "</option>";
            }
        ?>
    </select>
    <script>
        function locbaocao(value){
            window.location.href="LocTheoThanhVien?id=<?php echo $duan;?>&nv="+value
        }
    </script>
</div>     
<div id="duanhoatdong">
        <table>
            <thead>
                <tr>
                    <th>Người nạp</th>
                    <th class="congviec">Công việc hoàn thành</th>
                    <th class="congviec">Công việc kế tiếp</th>
                    <th class="mota">Mô tả thêm</th>
                    <th class="ngaythang">Ngày báo cáo</th>
                    <th>Tài liệu</th>
                </tr>
            </thead>
            
            <tbody>
                <?php
                    function the_excerpt($text) {
                        $sanitized = htmlentities($text, ENT_COMPAT, 'UTF-8');
                        if (strlen($sanitized) > 200) {
                            $cutString = substr($sanitized, 0, 200);
                            $words = substr($cutString, 0, strrpos($cutString, ' '));
                            return $words;
                        } else {
                            return $sanitized;
                        }
                    }
                    
                    for ($i=0; $i<sizeof($result); $i++){
                        echo "
                            <tr>
                                <td>{$result[$i]['HoTen']} </td>
                        ";
                        echo    "<td>".the_excerpt($result[$i]['MoTaCongViecHoanThanh']). "</td>";
                        echo    "<td>".the_excerpt($result[$i]['MoTaCongViecKeTiep']). "</td>";
                        echo    "<td>".the_excerpt($result[$i]['MoTaThem']). "</td>";
                        echo    "<td>{$result[$i]['NgayBaoCao']}</td>";
                        if($result[$i]['LinkFile']){
                            echo "<td><a href='../../{$result[$i]['LinkFile']}'>Download</a></td>";
                        } else {
                            echo "<td>{$result[$i]['LinkFile']}</td>";
                        }
                        echo "</tr>";
                    }
                ?>
            </tbody>
        </table>
</div>
